package com.enjoylearning.media.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.enjoylearning.media.model.po.MediaProcess;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author itcast
 */
public interface MediaProcessMapper extends BaseMapper<MediaProcess> {

    @Select("select * from meida_process where id%#{shardTotal} = #{shardIndex} and (status = 1 or status = 3) and file_count <3 limit #{count}")
    List<MediaProcess> selectListByShardingIndex(@Param("shardTotal") int shardTotal, @Param("shardIndex") int shardIndex, @Param("count") int count);

    @Update("update media_process set status = 4 where (status = 1 or status = 3) and fail_count < 3 and id = #{id}")
    Integer startTask(@Param("id") long id);
}
